<template>
  <div class="app-container">
    <el-row>
      <el-col :span="12">
        <el-calendar v-model="calendarValue"
                     :first-day-of-week="1">
          <template slot="dateCell" slot-scope="{ date, data }">
            <p class="Selected">
              {{ data.day.split('-').slice(2).join('-') }}
            </p>
          </template>
        </el-calendar>
      </el-col>
    </el-row>


    <!-- 开庭详情 -->
    <el-dialog class="ktxq" :title="xqtitle" :visible.sync="xqopen" width="600px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="案号">
              {{ form.ah }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="案件名称">
              {{ fsCase.ajmc }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="资产包">
              {{ fsCase.zfName }}&nbsp;&nbsp;{{ fsCase.batchName }}&nbsp;&nbsp;{{ fsCase.ssztmc }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="被告信息">
              {{ bgDsr.xm }}&nbsp;&nbsp;
              <dict-tag :options="dict.type.sys_user_sex" :value="bgDsr.xb"/>&nbsp;&nbsp;
              {{ bgDsr.zjhm }}&nbsp;&nbsp;
              电话：{{ bgDsr.sjhm }}&nbsp;&nbsp;<br>
              地址：{{ bgDsr.dz }}&nbsp;&nbsp;
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="开庭信息">
              {{ form.fymc }} &nbsp;&nbsp;<br> <b>{{ form.ktrq }}&nbsp;&nbsp;{{ form.ktsj }}&nbsp;&nbsp;</b>
              {{ form.ft }}&nbsp;&nbsp;
              <dict-tag :options="dict.type.fs_aj_ktlx" :value="form.ktfs"/>
            </el-form-item>
          </el-col>
          <el-col v-if="form.fgxx != null" :span="24">
            <el-form-item label="法官信息">
              {{ form.fgxx }}
            </el-form-item>
          </el-col>
          <el-col v-if="form.dlls != null" :span="24">
            <el-form-item label="代理律师">
              {{ form.dlls }}&nbsp;&nbsp;{{ form.dllssjh }}
              <br>
              <template v-for="(item,index) in form.lsFiles">
                <el-link :key="index" type="primary" :href="item.oosUrl" target="_blank">{{ item.name }}</el-link>
              </template>
            </el-form-item>
          </el-col>
          <el-col v-if="form.ktdx != null" :span="24">
            <el-form-item label="开庭短信">
              {{ form.ktdx }}
            </el-form-item>
          </el-col>
          <el-col v-if="form.ktcpxx != null || ktFiles.length>0" :span="24">
            <el-form-item label="开庭传票">
              {{ form.ktcpxx }}
              <br>
              <template v-for="(item,index) in form.ktFiles">
                <el-link :key="index" type="primary" :href="item.oosUrl" target="_blank">{{ item.name }}</el-link>
              </template>
            </el-form-item>
          </el-col>
          <el-col v-if="form.xcxxx != null" :span="24">
            <el-form-item label="小程序">
              {{ form.xcxxx }}
            </el-form-item>
          </el-col>
          <el-col v-if="form.tjfa != null" :span="24">
            <el-form-item label="调解方案">
              {{ form.tjfa }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="xqcancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOpencourt,
  getOpencourt,
  delOpencourt,
  addOpencourt,
  updateOpencourt,
  updateLs,
  updateZjzb
} from "@/api/fs/opencourt";
import {getRepaymentByCaseId, listBatch, listSszt, listZf} from "@/api/fs/case";
import {Div, Add, Sub, Mul, formatDate, formatNumber, toChineseNumber} from "@/api/fs/common";
import {delFile} from "@/api/fs/progress";
import {delPayFile} from "@/api/fs/pay";

export default {
  name: "Opencourt",
  dicts: ['fs_yes_no', 'fs_aj_ktlx', 'sys_user_sex'],
  data() {
    return {
      calendarValue: new Date(),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      UploadType: 2,
      fileKey: 0,
      // 案件进展开庭表格数据
      opencourtList: [],
      // 日期范围
      dateRange: [],
      ktFiles: [],
      lsFiles: [],
      // 弹出层标题
      title: "",
      xqtitle: "",
      // 是否显示弹出层
      open: false,
      xqopen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        processId: null,
        ah: null,
        caseId: null,
        fyid: null,
        fymc: null,
        ft: null,
        ktfs: null,
        ktrq: null,
        ktsj: null,
        tjy: null,
        fgxx: null,
        dllsid: null,
        dlls: null,
        lszjUrl: null,
        ktdx: null,
        ktcpxx: null,
        ktcpUrl: null,
        xcxxx: null,
        tjfa: null,
        zjzb: null,
        ajmc: null,
        zfid: null,
        batchId: null,
        nbajbh: null,
        ssztid: null,
      },
      // 表单参数
      form: {},
      lsform: {},
      fsCase: {},
      bgDsr: {},
    };
  },
  watch:{
    calendarValue(newVal, oldVal) {
      this.calendarValue = this.formatDate(newVal)
      // 这里就是我们处理数据，调用接口的位置
      this.judgeDate()
    }
  },
  created() {
  },
  methods: {
    // 格式化日期函数
    formatDate(date) {
      const value = new Date(date)
      const year = value.getFullYear()
      const month = (value.getMonth() + 1).toString().padStart(2, '0')
      const day = value.getDate().toString().padStart(2, '0')
      return `${year}-${month}-${day}`
    },
    async judgeDate() {
      console.log(this.calendarValue);
    },
    /** 查询案件进展开庭列表 */
    getList() {
      let params = {};
      if (this.queryParams.nbajbh) {
        params['nbajbh'] = this.queryParams.nbajbh;
      }
      if (this.queryParams.ajmc) {
        params['ajmc'] = this.queryParams.ajmc;
      }
      if (this.queryParams.zfid) {
        params['zfid'] = this.queryParams.zfid;
      }
      if (this.queryParams.batchId) {
        params['batchId'] = this.queryParams.batchId;
      }
      if (this.queryParams.ssztid) {
        params['ssztid'] = this.queryParams.ssztid;
      }
      this.queryParams.params = params;
      this.loading = true;
      listOpencourt(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.opencourtList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    xqcancel() {
      this.xqopen = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        processId: null,
        ah: null,
        caseId: null,
        fyid: null,
        fymc: null,
        ft: null,
        ktfs: null,
        ktrq: null,
        ktsj: null,
        tjy: null,
        fgxx: null,
        dllsid: null,
        dlls: null,
        lszjUrl: null,
        ktdx: null,
        ktcpxx: null,
        ktcpUrl: null,
        xcxxx: null,
        tjfa: null,
        zjzb: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        lsFiles: [],
        ktFiles: [],
        fileUrls: null,
        fsCase: null,
      };
      this.resetForm("form");
    },
    resetXq() {
      this.reset(),
        this.fsCase = {
          id: null,
          localId: null,
          bh: null,
          ah: null,
          bhLs: null,
          yg: null,
          ygbh: null,
          bg: null,
          bgbh: null,
          ajlx: null,
          ajlxMc: null,
          ajmc: null,
          bzqx: null,
          fyid: null,
          fymc: null,
          dzlx: null,
          sqbdje: null,
          sqlaay: null,
          sqlx: null,
          sqlxMc: null,
          zt: null,
          cjsj: null,
          gxsj: null,
          ownerId: null,
          owner: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          ajzt: null,
          tjyId: null
        };
      this.bgDsr = {
        id: null,
        localId: null,
        bh: null,
        dsrlx: null,
        xm: null,
        xb: null,
        nl: null,
        mz: null,
        csrq: null,
        dzlx: null,
        dz: null,
        dwmc: null,
        zy: null,
        zymc: null,
        gzdw: null,
        dwxz: null,
        zzlx: null,
        zzh: null,
        zybsjgszd: null,
        fddbr: null,
        fddbrzw: null,
        zjlx: null,
        zjhm: null,
        sjhm: null,
        gddh: null,
        cjsj: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleDetail(row) {
      this.resetXq();
      this.form = row;
      let ktrq = formatDate(row.ktrq, 'yyyy-MM-dd');
      this.form.ktrq = ktrq;
      this.fsCase = row.fsCase;
      this.bgDsr = row.fsCase.bgDsr;
      this.ktFiles = row.ktFiles;
      this.lsFiles = row.lsFiles;
      this.xqopen = true;
      this.xqtitle = "开庭详情";
    }
  }
};
</script>
<style scoped lang="scss">
.detail .el-form-item {
  margin-bottom: 0px;
}

.el-collapse-item__header {
  font-size: 16px !important;
  font-weight: 600 !important;
}

.el-table__cell .cell div {
  display: inline;
}

.el-table__cell .cell .btn {
  cursor: pointer;
}

.cellBtn button {
  font-size: 20px !important;
  padding: 0 !important;
}

.hktable .el-table__cell .cell div {
  display: inline-block;
}

.el-table__cell .cell .important {
  font-weight: 600;
}

.el-form-item__content div {
  display: inline-block;
}

.ktxq .el-dialog__body {
  padding: 0px 20px;
}

.ktxq .el-form-item {
  margin-bottom: 5px;
}

.el-calendar-table td.is-selected {
  background-color: #F2F8FE;
  border: 1px solid #1890ff !important;
}
.el-calendar-day p {
  margin: 0;
}
</style>
